package com.ironman.imes.device.framework.orm.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author 陈浩杰
 */
@Slf4j
@Component
public class MybatisPlusMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "isDelete", () -> "0", String.class);
        this.strictInsertFill(metaObject, "createdBy", () -> "userName", String.class);
        this.strictInsertFill(metaObject, "createdTime", Date::new, Date.class);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updatedBy", () -> "userName", String.class);
        this.strictUpdateFill(metaObject, "updatedTime", Date::new, Date.class);
    }
}
